<div id="maincontent">
	<div id="maincontent_inner">
		<div id="sidebar">
			<div class="menu single">
				<ul>
					<li><a href="#">注册用户管理</a>
						<ul>
							<li><a href="<?php echo site_url("c=user&m=index"); ?>">注册用户列表</a></li>
							<li class="current"><a href="<?php echo site_url("c=user&m=edit&uid=$uid"); ?>">编辑用户</a></li>
							<li><a href="<?php echo site_url("c=user&m=add"); ?>">添加用户</a></li>
						</ul>
					</li>
				</ul>
			</div>
		</div>
		<div id="content">
			<?php if($uid) {?>
			<div class="title">编辑用户</div>
			<?php }else {?>
			<div class="title">新增用户</div>
			<?php }?>

			<div class="infoarea">
				<form  id="editForm" name="editForm"  action="<?php echo site_url("c=user&m=$method&uid=$uid"); ?>" method="post">
				<input type="hidden" name="usereditsubmit" value="true" />
				<table border="0" cellspacing="0" cellpadding="0" width="100%" class="aev">
					<tr>
						<th>用户名:</th>
						<td><input type="text" class="half" name="username" value="<?php echo $username; ?>"/>
						<?php echo form_error('username'); ?>
						</td>
					</tr>
					<tr>
						<th>注册邮箱:</th>
						<td><input type="text" class="half" name="email" value="<?php echo $email; ?>"/>
						<?php echo form_error('email'); ?>
						</td>
					</tr>
					<tr>
						<th>更改密码:</th>
						<td><input type="password" class="half" id="password" name="password" value=""/>
						<?php echo form_error('password'); ?></td>
					</tr>
					<tr>
						<th>密码确认:</th>
						<td><input type="password" class="half" id="password2" name="password2" value=""/>
						<?php echo form_error('password2'); ?>
						</td>
					</tr>
				</table>
				<div class="box nav" style="margin-top:5px;margin-bottom:0;">
					&nbsp;<div style="float:right"><input type="submit" class="btn" value="确定"/><input type="button" class="btn" value="返回" onclick="gotoPage('<?php echo site_url("c=user&m=index"); ?>');" /></div>
				</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
 
	$(document).ready(function(){

		
		$("#editForm").validate({
			
			submitHandler:function(form){
				var username =$("#username").val();
				username ="username="+username;
				jQuery.ajax( {
					'type': 'post',
					'url': "<?php echo site_url("c=user&m=unique&uid=$uid"); ?>",
					'data': username,
					dataType:"json", 
					cache:false, 
					success:function( result ){ 
						if( result['success'] ){
							form.submit();
						}
						else
						{
							warning($("#username"),'该名称已经存在，请重新输入');
						}
					}
				});
			} ,

			rules:{
				username : {
					required:true,
					rangelength:[5,12]
				},
				email : {
					required:true,
					rangelength:[5,20],
					email:true
				} ,
				password : {
					required:true,
					rangelength:[5,20]
				},
				password2 : {
					required:true,
					rangelength:[5,20],
					equalTo:"#password"
				}
			},
			messages:{
				username : {
					required:"用户名不能为空",
					rangelength: $.format("用户名必须在{0}-{1}个字符之间")
				},
				email : {
					required:"注册邮箱不能为空",
					rangelength: $.format("注册邮箱必须在{0}-{1}个字符之间"),
				    email: "邮件格式错误，请重新输入"
				} ,
				password : {
					required:"密码不能为空",
					rangelength: $.format("密码必须在{0}-{1}个字符之间")
				} ,
				password2 : {
					required:"密码确认不能为空",
					rangelength: $.format("密码确认必须在{0}-{1}个字符之间"),
					equalTo:"两次输入的密码不一致"
				} ,
			} 
		});
	});

</script>